# Maintainer: David Runge <dvzrv@archlinux.org>

_name=Gem
pkgname=pd-gem
pkgver=0.94
pkgrel=11
pkgdesc="Graphics Environment for Multimedia"
arch=(loong64 x86_64)
url="https://github.com/umlaeute/Gem"
license=(GPL2)
groups=(pd-externals)
# TODO: potentially add gmerlin, libmpeg3 and glewmx (if that's still a thing)
depends=(assimp ftgl glew libdv libiec61883 pd sdl2 ttf-dejavu zlib)
makedepends=(imagemagick libvncserver vlc)
optdepends=('vlc: video capture support'
            'libvncserver: video capture support'
            'imagemagick: image processing support')
source=(
  "$pkgname-$pkgver.tar.gz::https://github.com/umlaeute/${_name}/archive/v${pkgver}.tar.gz"
  "$pkgname-0.94-error.patch"
)
sha512sums=('356e4f2a27131f927cd5d20ba9010088cc22930f313f61f54dd107db041b6cb2042ab5d530bae069e3ccdccd0a8fed1152631c6f187f4f4602f37d763356d316'
            '314fab766e93edfb41b3a97dce4d570dacb04390caf7e7f8aac86a2ad927029cad529d58302d65fb3453a2f9c6a03d361521a28db1933a6973087ea5f6f0320a')
b2sums=('1ca45c5a71e094aef04778538e6d0c83f4b13f233e6038507d5510ca904476f19ed1e70c011796e66e3688f8a8b40b13f823678b6b1baba877ac0b67eb9c6698'
        '2fab38f8ecaf99dc092017fef9a137943a66a9e5d8700455689f52a5ec485c997283abe81c892769671daf580820894ad78b62b9615ca92e6901919f55a33250')

prepare() {
  cd "${_name}-${pkgver}"
  # fix issues with error() calls: https://github.com/umlaeute/Gem/issues/287
  patch -Np1 -i ../"$pkgname-0.94-error.patch"
  autoreconf -fiv
}

build() {
  cd "${_name}-${pkgver}"
  ./configure --prefix=/usr \
              --with-default-font=/usr/share/fonts/TTF/DejaVuSans.ttf
  # prevent excessive overlinking due to libtool
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package() {
  make DESTDIR="$pkgdir/" install -C "${_name}-${pkgver}"
}
